package models

import (
	"fmt"
	"github.com/spf13/cast"
	"strings"
)

const RoleIdStrPrefix = "role_"
const UserIdStrPrefix = "user_"

// CasbinUserConvertStr id转换为str
func CasbinUserConvertStr(id int64, prefix string) string {
	return fmt.Sprintf("%s%d", prefix, id)
}

func CasbinUsersConvertStr(ids []int64, prefix string) []string {
	var users []string
	for _, v := range ids {
		users = append(users, CasbinUserConvertStr(v, prefix))
	}
	return users
}

// CasbinUserConvertId str转换为id
func CasbinUserConvertId(user string, prefix string) int64 {
	return cast.ToInt64(strings.TrimLeft(user, prefix))
}

func CasbinUsersConvertId(users []string, prefix string) []int64 {
	var ids []int64
	for _, v := range users {
		ids = append(ids, CasbinUserConvertId(v, prefix))
	}
	return ids
}
